#ifndef GERMTOOLS_H
#define GERMTOOLS_H

#include <QDebug>
#include <exception>
#include "imageprocessor.h"
#include "dataEntry.h"
#include "dataReader.h"
#include "neuralNetwork.h"
#include "neuralNetworkTrainer.h"
#include "mytype.h"
#include "BlobResult.h"

using namespace cv;

class GermTools
{
public:
    GermTools();
    ~GermTools();
    void autoContour(const Mat& src, Mat& dst, bool runNNFlag=false);
    void manualContour(const Mat& src, Mat& dst, bool runNNFlag=false);
    bool startTraining(QString& file, int method=1, int percent=50,int size=500, int step=100, int max=1500, int hidden=10,
                       int output=1);
    bool loadWeights(const QString &file, int hidden=10, int output=1);
    void runNeuralNetwork(Mat &nnImg);
    void setWavelet(bool checked);
    int getTotalSeeds() { return total; }
    int getSum() { return sum; }
    QList<SeedNode *> getSeedRegions() {return regions; }

private:    
    Rect estimateROI(const Mat& input);
    QList<SeedNode *> locateSeeds(const Mat& src_s, Mat& dst_rgb, bool runNNFlag = false);
    void generateData(const Mat& v, const QList<SeedNode *>& regions, bool runNNFlag = false);

private:
    QList<SeedNode *> regions;      // A square region of size 64 x 64 for each seed
    ImageProcessor *imgP;
    neuralNetwork *nNetwork;
    int total, sum;                 // 'total' seeds for each images, 'sum' of all images
    bool isWave;
};

class CBlobGetHeight : public COperadorBlob
{
public:
    double operator() (CBlob &blob)
    {
        return blob.GetBoundingBox().height;
    }

    const char *GetNom()
    {
        return "CBlobGetHeight";
    }
};

class CBlobGetWidth : public COperadorBlob
{
public:
    double operator() (CBlob &blob)
    {
        return blob.GetBoundingBox().width;
    }

    const char *GetNom()
    {
        return "CBlobGetWidth";
    }
};

class CBlobGetAspect : public COperadorBlob
{
public:
    double operator() (CBlob &blob)
    {
        Rect box = blob.GetBoundingBox();
        return box.height/box.width;
    }

    const char *GetNom()
    {
        return "CBlobGetAspect";
    }
};

#endif // GERMTOOLS_H
